#！/bin/bash
#################################################################
# @Description: 用例名称：操作系统支持GM/T 0003，测试目的：操作系统支持GM/T 0003规定的密码算法运算
# @Date : 2023-11-22
# @Last Modified by :
# @Last Modified time:2023-11-25
#################################################################
set -euo pipefail
res=0
echo  "1.生成SM2私钥"
openssl ecparam -genkey -name SM2 -out priv.key || res=1
echo "2.生成SM2公钥"
openssl ec -in priv.key -pubout -out pub.key  || res=1
echo  "3.创建测试文件"
echo 'test_string' >> readme.txt
echo "4.使用SM2私钥对readme.txt文件进行签名操作"
openssl pkeyutl -sign -inkey priv.key -in readme.txt -out sm2.sig || res=1
echo "5.使用SM2公钥验证签名"
openssl pkeyutl -verify -pubin -inkey pub.key -in readme.txt -sigfile sm2.sig || res=1

echo "判断用例执行是否成功" 
[ "$res" = "0" ] && echo -e "\033[32m-----------------test PASSED----------------\033[0m" || echo -e "\033[31m-----------------test FAILD----------------\033[0m"
echo "测试完成，开始环境清理"
rm -rf priv.key sm2.sig readme.txt pub.key